package com.lee.carinforecord;

public class CanDataTool {
    public static String byteToHex(byte[] bArr) {
        String byteStr = "";
        for (int i = 0; i < bArr.length; i++) {
            byteStr += a(i, bArr) + " ";
        }
        return byteStr;
    }

    public static String a(int paramInt, byte[] paramArrayOfByte) {

        if (paramInt >= paramArrayOfByte.length)
            return "00";
        return a(paramArrayOfByte).split(" ")[paramInt];
    }

    public static String a(byte[] paramArrayOfByte) {
        StringBuilder localStringBuilder = new StringBuilder("");
        if ((paramArrayOfByte == null) || (paramArrayOfByte.length <= 0))
            return "";
        int i = 0;
        while (true) {
            if (i >= paramArrayOfByte.length)
                return localStringBuilder.toString();
            String str = Integer.toHexString(paramArrayOfByte[i] & 0xFF);
            if (str.length() < 2)
                localStringBuilder.append(0);
            localStringBuilder.append(str + " ");
            i += 1;
        }
    }

    public static String a(String[] strArr, int i) {
        String str = "00000000";
        return (strArr == null || i < 0 || i >= strArr.length) ? str : strArr[i];
    }

    public static String b(String[] strArr, int i, int i2) {
        return a(strArr, i).charAt(i2) == '1' ? "mil" : "km";
    }

    public static double a(int i, int i2) {
        return (double) ((i * 256) + i2);
    }

    public static String a(int i, int i2, int i3) {
        double d = (double) ((((i * 256) * 256) + (i2 * 256)) + i3);
        if (d < 0.0d || d >= 1.6777215E7d) {
            return "empty";
        }
        return String.format("%.1f", new Object[]{Double.valueOf(d * 0.1d)});
    }



    public static String c(String str) {
        if (str == null || str.length() % 2 != 0) {
            return null;
        }
        String str2 = "";
        for (int i = 0; i < str.length(); i++) {
            String str3 = "0000" + Integer.toBinaryString(Integer.parseInt(str.substring(i, i + 1), 16));
            str2 = new StringBuilder(String.valueOf(str2)).append(str3.substring(str3.length() - 4))
                    .toString();
        }
        return str2;
    }


    public static int d(String str) {
        return Integer.parseInt(str, 2);
    }


    public static StringBuilder e(String str) {
        String[] split = str.split(" ");
        StringBuilder stringBuilder = new StringBuilder("");
        for (int i = 3; i < split.length - 1; i++) {
            stringBuilder.append(new StringBuilder(String.valueOf(c(split[i]))).append(" ").toString());
        }
        return stringBuilder;
    }

    public static String[] f(String str) {
        return e(str).toString().split(" ");
    }
}
